package com.hzsd.zengbanyi.biaodan_text.view;


import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.hzsd.zengbanyi.biaodan_text.R;
import com.hzsd.zengbanyi.biaodan_text.bean.WorkDAO;
import com.hzsd.zengbanyi.biaodan_text.utils.StandardTextChange;

/**
 * 循环遍历控件
 * @author Administrator
 *
 */
public class TraverseControl {
	private Context context;
	private WorkDAO dao;
	
	public TraverseControl(Context context){
		this.context = context;
		dao = new WorkDAO(context);
	}
	
	public void getView(View view,String type,String sampleId){
		ArrayList<String> names = new ArrayList<String>();
		ArrayList<String> units = new ArrayList<String>();
		ArrayList<String> nameSqls = new ArrayList<String>();
		if ("污染源".equals(type)) {
			names = getNameWRY();
			units = getUnitWRY();
			nameSqls = getNameWRYsql();
		}else{
			names = getNameHJZL();
			units = getUnitHJZL();
			nameSqls = getNameHJZLsql();
		}
		
		LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		layoutParams.setMargins(0, 10, 30, 10);
		LayoutParams etParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		etParams.setMargins(10, 0, 10, 0);
		
		for (int i = 0; i < names.size(); i++) {
			LinearLayout layout = new LinearLayout(context);
			layout.setOrientation(LinearLayout.HORIZONTAL);
			layout.setLayoutParams(layoutParams);
			
			TextView name = new TextView(context);
			EditText editText = new EditText(context);
			TextView unit = new TextView(context);
			
			editText.setBackgroundResource(R.drawable.input_kuang);
			
			editText.setTextColor(context.getResources().getColor(R.color.editText_gray));
			
			name.setTextSize(20);
			editText.setTextSize(20);
			unit.setTextSize(20);
			
			name.setText(names.get(i));
			editText.setText(dao.getStandard(sampleId, names.get(i)));
			unit.setText(units.get(i));
			
			editText.setLayoutParams(etParams);
			
			editText.setTag(names.get(i));
			editText.addTextChangedListener(new StandardTextChange(context, editText,sampleId));
			
			layout.addView(name);
			layout.addView(editText);
			layout.addView(unit);
			
			((ViewGroup)view).addView(layout);
		}
	}
	
	/**
	 * 排污口名称--污染源
	 * @return
	 */
	private ArrayList<String> getNameWRY() {
		ArrayList<String> arrayList = new ArrayList<String>();
		arrayList.add("流速");
		arrayList.add("宽度");
		arrayList.add("深度");
		arrayList.add("流量");
		arrayList.add("排放量");
		return arrayList;
	}
	/**
	 * 排污口名称对应数据库字段--污染源
	 * @return
	 */
	private ArrayList<String> getNameWRYsql() {
		ArrayList<String> arrayList = new ArrayList<String>();
		arrayList.add("wry_speed");
		arrayList.add("wry_width");
		arrayList.add("wry_depth");
		arrayList.add("wry_flow");
		arrayList.add("wry_emission");
		return arrayList;
	}
	
	/**
	 * 排污口单位--污染源
	 * @return
	 */
	private ArrayList<String> getUnitWRY() {
		ArrayList<String> arrayList = new ArrayList<String>();
		arrayList.add("m/s");
		arrayList.add("m");
		arrayList.add("m");
		arrayList.add("");
		arrayList.add("");
		return arrayList;
	}
	/**
	 * 现场水文名称--环境质量
	 * @return
	 */
	private ArrayList<String> getNameHJZL() {
		ArrayList<String> arrayList = new ArrayList<String>();
		arrayList.add("水位");
		arrayList.add("潮水");
		arrayList.add("流向");
		arrayList.add("断面宽");
		arrayList.add("水深");
		return arrayList;
	}
	/**
	 * 现场水文名称对应数据库字段--环境质量（地表水）
	 * @return
	 */
	private ArrayList<String> getNameHJZLsql() {
		ArrayList<String> arrayList = new ArrayList<String>();
		arrayList.add("dbs_waterlevel");
		arrayList.add("dbs_tide");
		arrayList.add("dbs_flow");
		arrayList.add("dbs_sectionwidth");
		arrayList.add("dbs_depth");
		return arrayList;
	}
	
	/**
	 * 现场水文单位--环境质量
	 * @return
	 */
	private ArrayList<String> getUnitHJZL() {
		ArrayList<String> arrayList = new ArrayList<String>();
		arrayList.add("");
		arrayList.add("");
		arrayList.add("");
		arrayList.add("");
		arrayList.add("");
		return arrayList;
	}

}
